package cfca.paperless.client.servlet._8_local;

import java.io.File;
import java.util.Date;

import org.apache.commons.io.FileUtils;

import cfca.paperless.client.bean.SignLocation;
import cfca.paperless.client.servlet.PaperlessClient;
import cfca.paperless.client.servlet.PaperlessClientLocal;
import cfca.paperless.client.servlet.PaperlessLocalConfig;
import cfca.paperless.client.util.IoUtil;

public class SealAutoPdfLocalTest02 {

    /**
     * 本地化签章，签名调用服务器的PDF自动化Hash签名接口，可以用于处理大文件和文件需要保密的场景
     * @param args
     * @throws IOException
     * @throws
     */
    public static void main(String[] args) throws Exception {
        try {
            long timeStart = System.currentTimeMillis();// 开始时间
            // 待签章pdf
            String filePath = "./TestData/file.pdf";
            byte[] pdf = FileUtils.readFileToByteArray(new File(filePath));
            // 印模图片
            byte[] imageData = FileUtils.readFileToByteArray(new File("./TestData/seal.png"));

            String sealCode = "org001sm2";// 印章编码
            String sealPassword = "11111111";// 印章密码
            SignLocation signLocation = new SignLocation("代理人签名", "R", 0, 0);// 签名位置
            signLocation = new SignLocation(1, 100, 100);

            // 初始化客户端对象
            PaperlessClient clientExtBean = new PaperlessClient(PaperlessLocalConfig.extUrl, 10000, 60000);// 无纸化辅助接口的访问URL

            // 以下代码为获取印章编码对应公钥证书
            PaperlessClient clientAssistBean = new PaperlessClient(PaperlessLocalConfig.assistUrl, 10000, 60000);// 无纸化辅助接口的访问URL

            PaperlessClientLocal paperlessClientLocal = new PaperlessClientLocal(clientExtBean, clientAssistBean, PaperlessLocalConfig.operatorCode);
            paperlessClientLocal.setPdfVerifyUrl("http://210.74.42.34:8000/PaperlessVerify/Pdf");
            byte[] sealedPdf = null;

            for(int i=0;i<1;i++) {
                pdf = paperlessClientLocal.sealAutoPdfLocal(pdf, sealCode, sealPassword, null, 1.0f, signLocation);
            System.out.println(i);
            }
            IoUtil.write("./TestData/output/sealAutoPdfLocalSM2-synthesizeAutoTemplate.pdf", pdf);
            
            long timeEnd = System.currentTimeMillis();// 结束时间
            System.out.println("time:" + (timeEnd - timeStart));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
   
}
